package com.blb.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.entity.*;
import com.blb.service.IOrderLogService;
import com.blb.service.IQualityService;
import com.blb.utils.DataTablePage;
import com.blb.utils.DataTablesPage;
import com.blb.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 质量追溯
 */
@Controller
@RequestMapping("/quality")
public class QualityController {

    @Autowired
    private IQualityService iQualityService;

    @Autowired
    private IOrderLogService iOrderLogService;
    @RequiresPermissions("quality")
    @ResponseBody
    @RequestMapping("quality")
    Quality isProduct(String productName){
        String name =productName.toString();
        Quality quality = iQualityService.fangWei(name,ShiroUtils.getCompany());
        return quality;
    }

    /**
     * 订单查询
     */
    @RequiresPermissions("productive")
    @ResponseBody
    @RequestMapping("goAway")
    DataTablesPage<Quality> orderDetial(Integer draw,int start,int length, String orderId){
        List<Quality> lists = iQualityService.selectRoad(start,length,orderId, ShiroUtils.getCompany());
        int i =  iQualityService.selAll(ShiroUtils.getCompany());
        return new DataTablesPage(draw,lists.size(),lists.size(), lists);
    }


    /**
     * 生产过程详细
     */
    @RequiresPermissions("productive")
    @RequestMapping("/log")
    String log(WebRequest req,Model model){
        String id = req.getParameter("data");
        System.out.println(id);
        QueryWrapper<OrderLog> wrapper = new QueryWrapper<>();
        wrapper.eq("orderId", id);
        List<OrderLog> logList = iOrderLogService.list(wrapper);
        model.addAttribute("logList",logList);
        return "quality/productive/productiveAll";
    }

}
